{% extends 'backstage/admin/manage_solution/base.html' %}
{% from 'bootstrap/pagination.html' import render_pagination %}

{% block solution_content %}
    {% if is_start() %}
        <h4>
            {{ _('Solutions') }}
            <small class="text-muted">{{ pagination.total|default(0) }}</small>
        </h4>
        {% if pagination.items %}
            <div class="table-responsive">
                <table class="table table-striped table-hover table-sm">
                    <thead>
                    <tr class="text-center">
                        <th>#</th>
                        <th>{{ _('Team number') }}</th>
                        <th>{{ _('Problem') }}</th>
                        <th>{{ _('UUID') }}</th>
                        <th>{{ _('Actions') }}</th>
                    </tr>
                    </thead>
                    {% for solution in pagination.items %}
                        <tr class="text-center">
                            <td>
                                {{ pagination.total - (config['SOLUTION_PER_PAGE'] * (page - 1) + loop.index) + 1 }}
                            </td>
                            <td>
                                <span class="badge badge-pill badge-info">
                                    {{ solution.team_number }}
                                </span>
                            </td>
                            <td>
                                <span class="badge badge-pill badge-primary">
                                    {{ solution.problem }}
                                </span>
                            </td>
                            <td>
                                <a href="{{ url_for('backstage.get_solution', filename=solution.uuid) }}"
                                   target="_blank">
                                    {{ solution.uuid }}
                                </a>
                            </td>
                            <td>
                                <button class="btn btn-danger btn-sm text-white" data-toggle="modal"
                                        data-target="#confirm-delete"
                                        data-href="{{ url_for('admin.delete_solution_task', solution_id=solution.id) }}">
                                    <span class="oi oi-trash"></span> {{ _('Delete') }}
                                </button>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            </div>
            <div class="page-footer">
                {{ render_pagination(pagination) }}
            </div>
        {% endif %}
    {% else %}
        {% include "backstage/tips/no_start.html" %}
    {% endif %}

    <!-- delete modal -->
    <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="confirmModalLabel"
         aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="confirmModalLabel">
                        {{ _('Delete Confirm') }}
                    </h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span class="oi oi-delete"></span>
                    </button>
                </div>
                <div class="modal-body">
                    <p>{{ _('Are you sure you want to delete this item?') }}</p>
                </div>
                <div class="modal-footer">
                    <form class="delete-form" method="post">
                        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            <span class="oi oi-action-undo"></span> {{ _('Cancel') }}
                        </button>
                        <button class="btn btn-danger btn-confirm" type="submit">
                            <span class="oi oi-trash"></span> {{ _('Delete') }}
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
